#!/bin/bash

# 设置默认值
export MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD:-123456}
export MYSQL_DATABASE=${MYSQL_DATABASE:-admin_app}
export MSSQL_SA_PASSWORD=${MSSQL_SA_PASSWORD:-YourStrong@Passw0rd}

# 检查配置文件是否存在
if [ ! -f "./server/config.json" ]; then
  echo "创建默认配置文件..."
  cat > ./server/config.json << EOF
{
  "databaseType": "sqlite",
  "databaseConfig": {
    "sqlite": {
      "storage": "./database.sqlite"
    },
    "mysql": {
      "host": "mysql",
      "port": 3306,
      "username": "root",
      "password": "$MYSQL_ROOT_PASSWORD",
      "database": "$MYSQL_DATABASE"
    },
    "sqlserver": {
      "server": "sqlserver",
      "port": 1433,
      "user": "sa",
      "password": "$MSSQL_SA_PASSWORD",
      "database": "admin_app"
    }
  }
}
EOF
fi

# 启动 Docker 容器
echo "启动 Docker 容器..."
docker-compose up -d

# 显示容器状态
echo "容器状态："
docker-compose ps

# 等待数据库服务就绪
echo "等待数据库服务就绪..."
sleep 10

# 显示日志
echo "应用日志："
docker-compose logs -f app 